﻿using System;
using NHibernate;
using WJ.Infrastructure.DDD;

namespace WJ.Infrastructure.NH
{
    public class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : class, IAggregateRoot, new()
    {
        private ISession session = NHContext.GetSession();

        public TEntity FindById(Guid Id)
        {
            return session.Get<TEntity>(Id);
        }

        public void Add(TEntity entity)
        {
            session.Save(entity);
        }

        public void Remove(TEntity entity)
        {
            session.Delete(entity);
        }

        public void Update(TEntity entity)
        {
            session.Update(entity);
        }

        public void UpSert(TEntity entity)
        {
            session.SaveOrUpdate(entity);
        }


    }
}